package org.myframework.rest;

import java.util.Map;

import javax.annotation.Resource;

import org.myframework.jdbc.SimpleCrud;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ISimpleCrud 对应的rest服务
 * <ol>
 * <li>{@link ISimpleCrud }</li>
 *
 * </ol>
 * @see
 * @author wanghui
 * @since 1.0
 * @2015年1月27日
 *
 */
@RestController
@RequestMapping(value = "")
public class SimpleCrudService   {

	@Resource(name = "simpleCrud")
	SimpleCrud simpleCrud ;

	@RequestMapping(value = "/simplecurd/{beanName}", method = RequestMethod.POST)
	public Map<String, Object>  save(@PathVariable String beanName, @RequestParam Map<String, Object> param) {
		simpleCrud.save(beanName, param);
		return param ;
	}

	@RequestMapping(value = "/simplecurd/{beanName}", method = RequestMethod.PUT)
	public  Map<String, Object> update(@PathVariable String beanName, @RequestParam Map<String, Object> param) {
		simpleCrud.update(beanName, param);
		return param ;
	}

	/**
	 * 当有中文参数值时需要使用
	 * @param beanName
	 * @param param
	 * @return
	 */
	@RequestMapping(value = "/simplecurd/{beanName}/update", method = RequestMethod.POST)
	public  Map<String, Object> update1(@PathVariable String beanName, @RequestParam Map<String, Object> param) {
		simpleCrud.update(beanName, param);
		return param ;
	}

	@RequestMapping(value = "/simplecurd/{beanName}", method = RequestMethod.DELETE)
	public Map<String, Object> delete(@PathVariable String beanName, @RequestParam Map<String, Object> param) {
		simpleCrud.delete(beanName, param);
		return param ;
	}

	@RequestMapping(value = "/simplecurd/{beanName}", method = RequestMethod.GET)
	public Map<String, Object> read(@PathVariable String beanName, @RequestParam Map<String, Object> param) {
		return simpleCrud.read(beanName, param);
	}


}
